const TokenKey = 'App-Token'
const UserKey  = 'App-UserInfo'
const IsLoginKey = 'isLogin'

export function getToken() {
  return uni.getStorageSync(TokenKey)
}

export function setToken(token) {
  return uni.setStorageSync(TokenKey, token)
}

export function removeToken() {
  return uni.removeStorageSync(TokenKey)
}

export function getUserInfo() {
  return JSON.parse(uni.getStorageSync(UserKey))
}

export function setUserInfo(userInfo) {
  userInfo.avatarUrl = userInfo.avatarUrl.replaceAll('?','%3F').replaceAll('=','%3D')
  return uni.setStorageSync(UserKey,JSON.stringify(userInfo))
}

export function removeUser() {
  return uni.removeStorageSync(UserKey)
}

export function getIsLogin() {
  return uni.getStorageSync(IsLoginKey)
}

export function setIsLogin(isLogin) {
  return uni.setStorageSync(IsLoginKey,isLogin)
}

export function removeIsLogin() {
  return uni.removeStorageSync(IsLoginKey)
}

export function clearStorageAll() {
	return uni.clearStorageSync()
}

export function getUserId() {
  const userInfo = uni.getStorageSync(UserKey);
  if (userInfo) {
    const parsedUserInfo = JSON.parse(userInfo);
    return parsedUserInfo.userId;
  }
  return null;
}
